package com.example.student;

import java.util.ArrayList;
import java.util.List;

public class StudentManage {

    /**
     * 班级信息
     * 
     */
    private static List<SchoolClass> classList = new ArrayList<>();

    /**
     * 增加班级
     */
    public void addClass(SchoolClass schoolClass) {
        if (schoolClass == null) {
            System.out.println("班级信息不能为空，请重新数入");
            return;
        }
        classList.add(schoolClass);
        System.out.println("班级【" + schoolClass.getClassname() + "】新增成功");
    }

    /**
     * 根据班级名称查询班级信息
     */
    public SchoolClass findSchoolClassByName(String className) {
        for (int i = 0; i < classList.size(); i++) {
            SchoolClass schoolClass = classList.get(i);
            if (className.equals(schoolClass.getClassname())) {
                return schoolClass;

            }

        }
        return null;

    }


     /**
     * 根据班级编号查询班级信息
     */
    public SchoolClass findSchoolClassByNo(String classNo) {
        for (int i = 0; i < classList.size(); i++) {
            SchoolClass schoolClass = classList.get(i);
            if (classNo.equals(schoolClass.getClassId())) {
                return schoolClass;

            }

        }
        return null;

    }

    /**
     * 返回所有班级信息
     * 
     * @param student
     */
    public List<SchoolClass> getAllSchoolClasses() {
        return classList;
    }

    /**
     * 增加学生
     */
    public void addStudent(Student student) {

    }

    /**
     * 删除学生
     */
    public void deleteStudent(Student student) {

    }

    /**
     * 通过学生名字查询学生信息
     */
    public List<Student> findStudentName(String name) {
        if(name==null){
            System.out.println("根据名字模糊查询时，学生名字不能为空");
            return null;
        }

        //返回的学生列表
        List<Student> studentList= new ArrayList<>();

        //循环查找学生名字
        for (SchoolClass schoolClass : classList) {
            List<Student> students=schoolClass.getStudents();
            for(Student student : students){
                if(student.getNeme().contains(name)){
                    studentList.add(student);
                }
            }
        }

        return studentList;
    }

    /**
     * 通过学生学号查询学生信息
     */
    public Student findStudentByNo(String no){
        if(no==null){
            System.out.println("根据名字模糊查询时，学生学号不能为空");
            return null;
        }

       

        //循环查找学生名字
        for (SchoolClass schoolClass : classList) {
            List<Student> students=schoolClass.getStudents();
            for(Student student : students){
                if(student.getNo().equals(no)){
                    return student;
                }
            }
        }

        return null;
    }




    /**
     * 通过学生学号查询学生成绩
     */
    public List<Student> findStudentCourseByNo(String StudentNo) {
        return new ArrayList<>();
    }

    public static void main(String[] args) {
        StudentManage manage = new StudentManage();
        // 新增班级
        SchoolClass schoolClass = new SchoolClass();
        schoolClass.setClassname("高一一班");
        manage.addClass(schoolClass);
        manage.getClass();
        List<SchoolClass> allSchoolClasses = manage.getAllSchoolClasses();
        System.out.println(allSchoolClasses);
    }
}
